package work5;

//编写一个Car类，具有String类型的属性品牌，具有功能drive；
//
//定义其子类Aodi和Benchi，具有属性：价格、型号；具有功能：变速；
//
//定义主类E，在其main方法中分别创建Aodi和Benchi的对象并测试对象的特性。
public class Car {
    private String brand;

    public void drive(){
        System.out.println(getBrand()+"汽车：");
    }

    public Car() {
    }

    public Car(String brand) {
        this.brand = brand;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }
}

class Aodi extends Car{
    private double price;
    private String type;

    public void drive(){
        super.drive();
        System.out.println("价格："+getPrice()+"\n型号："+getType());
        System.out.println("具有功能：变速！");
    }

    public Aodi() {
    }

    public Aodi(String brand, double price, String type) {
        super(brand);
        this.price = price;
        this.type = type;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if (price<0){
            System.out.println("价格必须大于0");
            return;
        }
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

class Benchi extends Car{
    private double price;
    private String type;

    public void drive(){
        super.drive();
        System.out.println("价格："+getPrice()+"\n型号："+getType());
        System.out.println("具有功能：变速！");
    }

    public Benchi() {
    }

    public Benchi(String brand, double price, String type) {
        super(brand);
        this.price = price;
        this.type = type;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if (price<0){
            System.out.println("价格必须大于0");
            return;
        }
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
    public static void main(String[] args) {
        Aodi aodi =new Aodi("奥迪",279999,"2021款 35 TFSI 进取致雅型");
        aodi.drive();
        Benchi benchi =new Benchi("奔驰",430200,"2021款 E 260 L");
        benchi.drive();
    }
}
